<template>
    <div class="UserSelect">
        <MyDialog :model-value="true" title="选择用户" :type="DialogType.C3" @close="onClose" append-to-body>
            <User ref="UserRef" isSelect divHeight="calc(100vh - 349px)" :checkbox-config="checkboxConfig" :radio-config="radioConfig" @setSelectData="onSetSelectData" v-bind="$attrs"></User>

            <template #footer>
                <el-button type="primary" plain @click="onOK">确定</el-button>
            </template>
        </MyDialog>
    </div>
</template>

<script lang="ts" setup>
import { DialogType } from "@/_gx/TsEnums";
import User from "./User.vue";

//定义2种config
const checkboxConfig = { trigger: "row" };
const radioConfig = { trigger: "row" };

//定义选择的userID，可能是单个值，可能是数组，一般情况是单个值（即如果是单选，则回显时选中；如果是多选，则回显时把数据隐藏）
const selectUserID = ref<any>();

//调用已经选择的用户ID
const SetSelectUserID = (userID) => {
    selectUserID.value = userID;
};

//设置回显时界面上的选择
const onSetSelectData = () => {
    nextTick(() => {
        UserRef.value.UserDataTableRef.SetSelectData(selectUserID.value);
    });
};

//定义User的Ref对象
const UserRef = ref(null);

//确定
const onOK = () => {
    //得到选择的数据
    let selectData = UserRef.value.UserDataTableRef.GetSelectData();

    if (Gx.IsEmpty(selectData) || selectData.length == 0) {
        App.Tips({ msg: "未选择任何数据！" });
        return;
    }

    emits("close", selectData);
};

//关闭
const onClose = () => {
    emits("close");
};

const emits = defineEmits(["close"]);
defineExpose({ SetSelectUserID });
</script>
